package com.aidisp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aidisp.dao.UserDao;
import com.aidisp.model.admin.User;
import com.aidisp.service.UserService;
import com.aidisp.util.StringUtil;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;
	
	@Override
	public User findUserByID(String loginName) {
		return userDao.getById(User.class, loginName);
	}
	@Override
	public User findUserLogin(User user){
		User loginUser = findUserByID(user.getLoginName());
		return loginUser;
		
	}

	@Override
	public void add(User user) {
		user.setPassword(StringUtil.md5(user.getPassword()));
		this.userDao.save(user);
		
	}

	@Override
	public void edit(User user) {
		this.userDao.update(user);
	}

	@Override
	public List<User> findAllUser() {
//		List<Class> groupClass = new ArrayList<Class>();
//		groupClass.add(Group.class);
//		this.userDao.findAllEntityJoinFetch(User.class,groupClass);
		
//		return userDao.findAllEntityJoinFetch(User.class, groupClass);
		return userDao.findAllEntity(User.class);
	}
	
	
}
